package br.consultorio.digital.dao;

import java.util.ArrayList;

import android.app.Activity;

public class DAOAgendaData extends DAO {

	// private Activity activityAtividadeData;
	private static DAOAgendaData instance;

	public static DAOAgendaData getInstance(Activity context) {
		if (instance == null) {
			synchronized (DAOAgendaData.class) {

				if (instance == null) {
					instance = new DAOAgendaData();
					abrecriaBanco(context);
				}
			}
		}
		return instance;
	}

	/**
	 * Busca e recupera o AtividadeData pesquisado.
	 * 
	 * @param nomeAtividadeData
	 * @return
	 */

	public ArrayList<Object> consultarDh_agenda(String data) {
		setCursor(getDatabase()
				.query("tb_agenda as a",
						new String[] { "distinct a.dt_agenda" },
						"a.dt_agenda like '" + data + "'",
						null,
						null,
						null,
						"SUBSTR(a.dt_agenda, 7, 4), SUBSTR(a.dt_agenda, 4, 2), SUBSTR(a.dt_agenda, 1, 2)"));

		ArrayList<Object> ap = new ArrayList<Object>();

		while (getCursor().moveToNext()) {
			ap.add(getCursor().getString(
					getCursor().getColumnIndexOrThrow("dt_agenda")));
		}

		fechaBanco();
		return ap;
	}

	public ArrayList<Object> consultarTodos() {
		setCursor(getDatabase()
				.query("tb_agenda as a",
						new String[] { "distinct a.dt_agenda" },
						null,
						null,
						null,
						null,
						"SUBSTR(a.dt_agenda, 7, 4), SUBSTR(a.dt_agenda, 4, 2), SUBSTR(a.dt_agenda, 1, 2)"));

		ArrayList<Object> ap = new ArrayList<Object>();

		while (getCursor().moveToNext()) {
			ap.add(getCursor().getString(
					getCursor().getColumnIndexOrThrow("DT_Agenda")));
		}

		fechaBanco();
		return ap;
	}
}
